package com.lb.ai.swagger.controller;

import com.lb.ai.common.response.Result;
import com.lb.ai.common.response.ResultBuilder;
import com.lb.ai.common.utils.JsonUtils;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.Data;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 示例控制器
 * 用于展示API文档的使用方法
 *
 * @author LiuJianning
 */
@Tag(name = "示例接口", description = "用于展示Knife4j接口文档的使用")
@RestController
@RequestMapping("/api/demo")
public class DemoController {

    @Operation(summary = "GET请求示例", description = "演示一个简单的GET请求")
    @GetMapping("/hello")
    public Result<String> hello(@Parameter(description = "用户名") @RequestParam(required = false) String username) {
        return ResultBuilder.<String>create()
                .success(true)
                .data("Hello " + (username != null ? username : "World"))
                .build();
    }

    @Operation(summary = "POST请求示例", description = "演示一个简单的POST请求", security = @SecurityRequirement(name = "Authorization"))
    @PostMapping("/user")
    public Result<UserDTO> createUser(@RequestBody UserDTO userDTO, @RequestHeader Map<String,String> map) {
        System.out.println(JsonUtils.toJsonString(map));
        // 模拟创建用户
        return Result.ok(userDTO);
    }

    @Data
    public static class UserDTO {
        @Schema(description = "用户名")
        private String username;

        @Schema(description = "年龄")
        private Integer age;

        @Schema(description = "邮箱")
        private String email;
    }
} 